package parsers;

import java.net.HttpURLConnection;
import java.net.URL;

import main.WoTCWBot;

import utils.Utils;

import data.wg.MapInfo;



public class HTMLParser 
{

	public static MapInfo getMapInfo(String mapid)
	{
		MapInfo mf = new MapInfo();
		try
		{
			URL ClanURL = new URL("http://cw.worldoftanks.eu/clanwars/maps/provinces/"+mapid+"/");
			HttpURLConnection httpConn = (HttpURLConnection) ClanURL.openConnection();
			httpConn.setDoOutput(true);
			String response = Utils.convertStreamToString(httpConn.getInputStream());
			//System.out.println(response);
			
			int a = response.indexOf("js-dialog-title\">");
			String provincename = response.substring(a+17, response.indexOf("<", a+17));
			
			int b= response.indexOf("nodelimiter b-name-map\"> ");
			String mapname = response.substring(b+25,response.indexOf("<", b+25)-1);
			
			
			mf.name=provincename;
			mf.mapname=mapname;
			//System.out.println("##############"+mf.name);
			//System.out.println("##############"+mf.mapname);
			
			
		}
		catch(Exception e)
		{
			WoTCWBot.LOGGER.fatal("cant fetch mapinfo: "+e);
		}
		return mf;
	}
	
}
